package com.ny.controller;

import com.ny.entity.Device;
import com.ny.entity.Result;
import com.ny.service.DeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/device")
public class DeviceController {

    @Autowired
    private DeviceService deviceService;

    // 查询所有设备接口
    @GetMapping("/findAll")
    public Result findAll() {
        List<Device> devices = deviceService.findAllDevices();
        return Result.success(devices);  // 使用统一响应格式返回数据
    }
    
    // 添加设备接口
    @PostMapping("/add")
    public Result addDevice(@RequestBody Device device) {
        Device savedDevice = deviceService.addDevice(device);
        return Result.success(savedDevice);
    }
}